[JENKINS-75986] Refactor BuildReferenceMapAdapter#10946
[JENKINS-75986] Refactor BuildReferenceMapAdapter#10946timja merged 9 commits intojenkinsci:masterfrom
BuildReferenceMapAdapter#10946Conversation
b041c39 to
c6fbfab
Compare
45a16a8 to
ab0488f
Compare
BuildReferenceMapAdapter
b082ffd to
d6f5d21
Compare
…sage - Reuse the standard collection base classes (AbstractMap, AbstractSet, AbstractCollection) to avoid redundant code. - Treat BuildReferenceMapAdapter strictly as a read-only view (except for the case where iterator remove() delegation is required for core), and remove unnecessary mutation methods. - Move the Spliterator customizations from AbstractLazyLoadRunMap into BuildReferenceMapAdapter so that entrySet(), values(), and keySet() implementations can be reused. - Align BuildReferenceMapAdapter with the weak consistency semantics of RunMap (e.g., size() may be approximate, but isEmpty() should remain reliable).
d6f5d21 to
48768b1
Compare
| /** | ||
| * Add a <em>new</em> build to the map. | ||
| * Do not use when loading existing builds (use {@link #put(Integer, Object)}). | ||
| * Do not use when loading existing builds (use {@link #putAll(Map)}). |
There was a problem hiding this comment.
Left over from the LazyBuildMixIn change in #10759 I guess.
| entry = iterator.next(); | ||
| assertEquals(3, entry.getKey().intValue()); | ||
| assertEquals("[5, 3, 1]", a.getLoadedBuilds().keySet().toString(), ".next() precomputes the one after that too"); | ||
| assertEquals("[5, 3]", a.getLoadedBuilds().keySet().toString()); |
There was a problem hiding this comment.
As I understand it, this behavioral change is just being lazier about loading builds from the entry set iterator.
| } else | ||
| throw new NoSuchElementException(); | ||
| return entryOf(last); | ||
| } |
There was a problem hiding this comment.
It how it was before - R next = owner.newestBuild(); - was resolved during iterator initialization,
then next() will resolve the next on at place
| for (R i = start; i != end; ) { | ||
| i = search(getNumberOf(i) - 1, DESC); | ||
| assert i != null; | ||
| } |
There was a problem hiding this comment.
Unclear to me what this loop was even doing (when assertions are disabled).
There was a problem hiding this comment.
This code should be removed in scope of #10759. As far as I understood, this loop was loading builds which belong to subMap interval to Index.
There was a problem hiding this comment.
Now AbstractLazyLoadRunMap.core (which replaces Index) has all set of build references available on disk by design
core/src/main/java/jenkins/model/lazy/BuildReferenceMapAdapter.java
Outdated
Show resolved
Hide resolved
core/src/main/java/jenkins/model/lazy/BuildReferenceMapAdapter.java
Outdated
Show resolved
Hide resolved
| if (val == null) { | ||
| return null; | ||
| } | ||
| return removeValue(val) ? val : null; |
There was a problem hiding this comment.
Would be nicer to remove the key without resolving it, but that would violate the remove signature. Not sure if this is ever actually called on an unloaded build to begin with.
There was a problem hiding this comment.
I made BuildReferenceAdapter readonly new of core, all modification expected to be done using core directly. But to reuse navigation collection and it's iterator.remove() functionality, I delegated removing to class, resposible of core modification (AbstractLazyLoadRunMap). The logic we have there relies on removeValue(R) method. So looks like there is noting I can do. Maybe in next PRs if I or somebody else find a way
core/src/main/java/jenkins/model/lazy/BuildReferenceMapAdapter.java
Outdated
Show resolved
Hide resolved
core/src/main/java/jenkins/model/lazy/BuildReferenceMapAdapter.java
Outdated
Show resolved
Hide resolved
core/src/main/java/jenkins/model/lazy/BuildReferenceMapAdapter.java
Outdated
Show resolved
Hide resolved
core/src/main/java/jenkins/model/lazy/BuildReferenceMapAdapter.java
Outdated
Show resolved
Hide resolved
jglick
left a comment
There was a problem hiding this comment.
Minor suggestions, but looks good from what I can tell. I am running some tests in CloudBees CI.
|
(remember to push any follow-up changes as new commits to the PR branch rather than force-pushing, to make it easier for reviewers to track progress) |
….java Co-authored-by: Jesse Glick <jglick@cloudbees.com>
….java Co-authored-by: Jesse Glick <jglick@cloudbees.com>
|
Compilation errors in |
jglick
left a comment
There was a problem hiding this comment.
(once tests here are fixed, and if I can get this tested in CloudBees CI)
|
This is a great improvement. I don't think I'll have time to review it in detail, but linking #5942 for some history that might be relevant. Thanks again for the great contribution! |
timja
left a comment
There was a problem hiding this comment.
Thanks!
/label ready-for-merge
This PR is now ready for merge, after ~24 hours, we will merge it if there's no negative feedback.
Thanks!
See JENKINS-75986.
AbstractLazyLoadRunMap uses BuildReferenceMapAdapter, but there is a lot of code doing a similar job in both classes.
Also, BuildReferenceMapAdapter implements the Map interface instead of extending AbstractMap, which leads to re-implementing trivial methods such as hashCode(), equals(), toString(), and toArray().
Suggested changes for BuildReferenceMapAdapter:
Testing done
Manual testing on my local environment,
Proposed changelog entries
Proposed changelog category
/label internal
Proposed upgrade guidelines
N/A
Submitter checklist
@Restrictedor have@since TODOJavadocs, as appropriate.@Deprecated(since = "TODO")or@Deprecated(forRemoval = true, since = "TODO"), if applicable.evalto ease future introduction of Content Security Policy (CSP) directives (see documentation).Desired reviewers
@jglick
Before the changes are marked as
ready-for-merge:Maintainer checklist
upgrade-guide-neededlabel is set and there is a Proposed upgrade guidelines section in the pull request title (see example).lts-candidateto be considered (see query).